package com.lifesea.system.api.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lifesea.base.entity.PagingRequest;
import com.lifesea.commons.utils.Utils;
import com.lifesea.dao.mapper.extra.SysLogExtMapper;
import com.lifesea.model.SysLog;
import com.lifesea.model.SysLogExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service()
public class SysLogService {

  //  private static Logger logger = LoggerFactory.getLogger(SysLogService.class);

    @Autowired
    private SysLogExtMapper sysLogMapper;


    private SysLogExample getExample(Map map) {
        SysLogExample example = new SysLogExample();
        SysLogExample.Criteria criteria = example.createCriteria();

        if (map != null && map.size() > 0) {
            if (Utils.hasKeyNotEmpty(map, "orderbyclause")) example.setOrderByClause(Utils.toString(map.get("orderbyclause")));
            if (Utils.hasKeyNotEmpty(map, "logNumber")) criteria.andLogNumberEqualTo(Utils.toLong(map.get("logNumber")));
            if (Utils.hasKeyNotEmpty(map, "logAcount")) criteria.andLogAcountEqualTo(Utils.toString(map.get("logAcount")));
            if (Utils.hasKeyNotEmpty(map, "logModule")) criteria.andLogModuleEqualTo(Utils.toString(map.get("logModule")));
            if (Utils.hasKeyNotEmpty(map, "logOperate")) criteria.andLogOperateEqualTo(Utils.toString(map.get("logOperate")));

          /*  if (map.containsKey("did")) criteria.andIdEqualTo(Utils.toInteger(map.get("did")));
            if (map.containsKey("uids")) criteria.andUidIn((List<Integer>) map.get("uids"));
            if (map.containsKey("id_in")) criteria.andIdIn((List<Integer>) map.get("id_in"));
            if (map.containsKey("easemod_username"))
                criteria.andEasemodUsernameEqualTo(Utils.toString(map.get("easemod_username")));*/

        }

        return example;
    }

    public Integer count(HashMap map) {
        return sysLogMapper.countByExample(getExample(map));
    }

    public List<SysLog> find(Map conditionBean) {
        return sysLogMapper.selectByExample(getExample(conditionBean));
    }

    public PageInfo<SysLog> pageList( PagingRequest pagingRequest,Map conditionBean) {
        PageHelper.startPage(pagingRequest.getPageNum(), pagingRequest.getPageSize());
        return new PageInfo<SysLog>(sysLogMapper.selectByExample(getExample(conditionBean)));
    }
    public SysLog findOne(Long id) {
        return sysLogMapper.selectByPrimaryKey(id);
    }

    public Integer update(SysLog record) {
        return sysLogMapper.updateByPrimaryKeySelective(record);
    }
    public Integer save(SysLog record) {
        return sysLogMapper.insert(record);
    }

    public int saveGeneratedKeys(SysLog record) {
        return sysLogMapper.insertGeneratedKeys(record);
    }
    public Integer delete(Long id) {
        return sysLogMapper.deleteByPrimaryKey(id);
    }



}
